using System;
using System.Reflection;
using UnityEngine;
using System.Collections.Generic;
using System.Linq;

namespace EntityKit.Runtime
{
    public static partial class BindService
    {
        private static void BindGameObject(Component component, FieldInfo field)
        {
            var bindAttr = GetCustomAttributeWithCache<GameObjectBindAttribute>(field);
            if (bindAttr == null) return;
            var gameObject = FindTransformWithPathCache(component.transform, bindAttr.Path)?.gameObject;
            if (gameObject != null)
            {
                field.SetValue(component, gameObject);
            }
            else
            {
                Debug.LogError($"对象绑定失败：路径 {bindAttr.Path} 未找到 GameObject");
            }
        }
    }
}